<!DOCTYPE html	PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" xmlns:sdu="http://sduept.com/jsf/cc">
<h:head>
	<link href="/css/primefaces/menubase.css" rel="stylesheet"
		type="text/css" />
	<title>人员选择器</title>
		<style type="text/css">
.value {
	font-weight: bold;
}

.ui-tree {
	width: 400px;
	position: relative;
	height: 500px;
	overflow-y: scroll;
}

input[type="text"] {
	height: 21px;
}
</style>
</h:head>
<h:body>
	<!-- 
	layer.js打开的窗口中用到用户选择器时，选择本页面。
	需要在父xhtml中添加primeface代码：
	<p:commandButton value="添加主保护" onclick="openNeedDeviceDialog('zbhdz','#{acLineFaultReportController.faultReportMain.faultRecord.equipment_id}','#{acLineFaultReportController.secondStationDetail.stationId}');" icon="ui-icon-document"/>
	<p:remoteCommand name="onUserDialogReturn" update="" actionListener="#{acLineFaultReportController.onUserDialogReturn}" />
	需要在父xhtml中添加script代码：
	var userDialogIndex;
	//此方法与上面添加的commandButton方法名和参数一致即可
	function openUserChooseDialog(){
		//打开页面
		userDialogIndex = layer.open({
			  type: 2,
			  maxmin :false,
			  area: ['420px', '662px'],
			  fixed: false, //不固定
			  title:'人员选择器',
			  maxmin: true,
			  content: '/ui/common/org_selector_user_single_layer.xhtml'
			});
	}
	//此方法名不可更改
	function dialogReturn(index,data){
		var params = [];
		data = eval("("+data+")");
		if(index == userDialogIndex){
			params.push({name:'className',value:data.className},{name:'userJson',value:data.data});
			onUserDialogReturn(params);
		}
	}
	需要在打开此选择器的页面的controller中添加如下方法：
	//此方法与primeface中调用的方法名一致即可
	public void onUserDialogReturn() {
		String userJson = getParameter("userJson");
		String className = getParameter("className");
		if(PersonnelEntityBean.class.getSimpleName().equals(className) && StringUtils.isNoneBlank(userJson) ){
			PersonnelEntityBean user = JSONObject.parseObject(userJson, PersonnelEntityBean.class);
			DepartmentEntityBean group = user.getGroup();
			faultReportMain.setReportPerson(user.getName());
			faultReportMain.setReportUnit(group.getName());
    	}
	}
	} -->
 	<h:form id="opForm">
 		<p:toolbar style="width:380px">
			<f:facet name="left">
				<p:commandButton value="确定" icon="ui-icon-disk" update="selectedPersons" oncomplete="closeAndSave();"
					 actionListener="#{orgSelectorSingleLayerController.selectedPerson}" />
			</f:facet>
		</p:toolbar>
		<h:inputHidden id="selectedPersons" value="#{orgSelectorSingleLayerController.selectedPersonJson}" />
 	</h:form>
	<h:form id="personForm">
		<!-- 选择操作人 -->
		<p:panel style="height:500px;width:385px;border:0">
			<p:tree value="#{orgSelectorSingleLayerController.deptPerson}" var="node" dynamic="true" selectionMode="single" id="personTree"
				widgetVar="personTree" animate="true" style="border:0;width:380px;">
				<p:ajax event="expand" update=":personForm:personTree"
					listener="#{orgSelectorSingleLayerController.onNodeExpand}" />
				<p:ajax event="select"
					listener="#{orgSelectorSingleLayerController.onPersonNodeSelect}" />
				<p:treeNode type="dept" icon="fa fa-home">
					<h:outputText value="#{node}" />
				</p:treeNode>
				<p:treeNode type="user" icon="fa fa-user">
					<h:outputText value="#{node}" />
				</p:treeNode>
				<p:treeNode type="default" icon="fa fa-home">
					<h:outputText value="#{node}" />
				</p:treeNode>
			</p:tree>
		</p:panel>
	</h:form>
	<script>
		function closeAndSave(){
			var index = parent.layer.getFrameIndex(window.name);
			var jsonData = document.getElementById("opForm:selectedPersons").value;
			if(parent.dialogReturn){
				parent.dialogReturn(index,jsonData);
			}
			parent.layer.close(index);
		}
	</script>
</h:body>
</html>
